<?php declare(strict_types=1);


namespace App\Services\Store;

use App\Models\AbcquietStores;
use App\Models\AbcStores;
use App\Models\AlipayAppOauthUsers;
use App\Models\AlipayZftStore;
use App\Models\AllinpayStores;
use App\Models\CcbStores;
use App\Models\CibpayStore;
use App\Models\CoolStores;
use App\Models\CqcbankStores;
use App\Models\EasypayaStore;
use App\Models\EasypayStore;
use App\Models\FuiouStore;
use App\Models\GsNongjinStores;
use App\Models\HkrtStore;
use App\Models\HwcpayStore;
use App\Models\JdStore;
use App\Models\LianfuStores;
use App\Models\LianfuyoupayStores;
use App\Models\LinkageStores;
use App\Models\MerchStores;
use App\Models\MyBankStore;
use App\Models\NewLandStore;
use App\Models\NongjinStores;
use App\Models\PinganStores;
use App\Models\SaobeiStores;
use App\Models\VbillaStore;
use App\Models\VbillStore;
use App\Models\WeixinaStore;
use App\Models\WeixinStore;
use App\Models\WftpayStore;
use App\Models\WingStores;
use App\Models\YinkaStore;
use Illuminate\Support\Facades\DB;

class StoreMchService
{
    /**
     * 获取店铺通道的商户号
     * @param string $store_id
     * @param string $company
     * @return string
     */
    public static function getMchNo(string $store_id, string $company): string
    {
        $mchNo = "";
        switch ($company) {
            case "jiujiang":
                $mchinfo = DB::table('jiujiang_stores')->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mchtNo;
                }
                break;

            case "nongjin":
                $mchinfo = DB::table("nongjin_stores")->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchantNo;
                }
                break;

            case "pingan":
                $mchinfo = PinganStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchant_id;
                }
                break;

            case "gs_nongjin":
                $mchinfo = GsNongjinStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "abc":
                $mchinfo = AbcStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "abc_quiet":
                $mchinfo = AbcquietStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchant_id;
                }
                break;

            case "allinpay":
                $mchinfo = AllinpayStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->cusid;
                }
                break;

            case "unionpay_merch":
                $mchinfo = MerchStores::query()->where('store_id', $store_id)->where("version", "v1")->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "unionpay_merch_v2":
                $mchinfo = MerchStores::query()->where('store_id', $store_id)->where("version", "v2")->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "wingpay":
                $mchinfo = WingStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
//                   'institutionCode',
//                   'merchantNo',
                    $mchNo = $mchinfo->merchantNo;
                }
                break;

            case "saobei":
                $mchinfo = SaobeiStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchantNo;
                }
                break;

            case "ccb":
                $mchinfo = CcbStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchantid;
                }
                break;

            case "cool":
                $mchinfo = CoolStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchantNo;
                }
                break;

            case "alipay":
                $mchinfo = AlipayAppOauthUsers::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->alipay_store_id;
                }
                break;

            case "weixin":
                $mchinfo = WeixinStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->wx_sub_merchant_id;
                }
                break;

            case "weixina":
                $mchinfo = WeixinaStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->wx_sub_merchant_id;
                }
                break;

            case "fuiou":
                $mchinfo = FuiouStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mchnt_cd;
                }
                break;

            case "vbill":
                $mchinfo = VbillStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mno;
                }
                break;

            case "vbilla":
                $mchinfo = VbillaStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mno;
                }
                break;

            case "jdjr":
                $mchinfo = JdStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merchant_no;
                }
                break;
            case "mybank":
                $mchinfo = MyBankStore::query()->where('OutMerchantId', $store_id)->select('MerchantId')->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }

                break;

            case "newland":
                $mchinfo = NewLandStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->nl_mercId;
                }
                break;


            case "lianfu":
                $mchinfo = LianfuStores::query()->where('store_id', $store_id)->select('apikey as MerchantId', 'signkey', 'appid')->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "zft":
                $mchinfo = AlipayZftStore::query()->where('store_id', $store_id)->select('smid as MerchantId', 'order_id')->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "lianfuyoupay":
                $mchinfo = LianfuyoupayStores::query()->where('store_id', $store_id)
                    ->select(
                        'apikey as MerchantId',
                        'signkey',
                        'pos_sn',
                        "type"
                    )
                    ->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->MerchantId;
                }
                break;

            case "hkrt":
                $mchinfo = HkrtStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->merch_no;
                }
                break;


            case "easypay":
                $mchinfo = EasypayStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->termMercode;
                }
                break;
            case "easypaya":
                $mchinfo = EasypayaStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->termMercode;
                }
                break;
            case "linkage":
                $mchinfo = LinkageStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->acqMerId;
                }
                break;


            case "wftpay":
                $mchinfo = WftpayStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }

                break;

            case "cib":
                $mchinfo = CibpayStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;

            case "cqcbank":
                $mchinfo = CqcbankStores::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;


            case "hwcpay":
                $mchinfo = HwcpayStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;

            case "yinka":
                $mchinfo = YinkaStore::query()->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->sn;
                }
                break;

            case "cmbc":
                $mchinfo = DB::table('cmbc_stores')->where('store_id', $store_id)->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;
            case "yinsheng":
                $mchinfo = DB::table('yinsheng_stores')->where(['store_id' => $store_id])->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->seller_id;
                }
                break;

            case "dongguan":
                $mchinfo = DB::table('dongguanbank_stores')
                    ->where(['store_id' => $store_id])
                    ->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;

            case "lakala":
                $mchinfo = DB::table('lakala_stores')
                    ->where(['store_id' => $store_id])
                    ->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;
            case "lianhou":
                $mchinfo = DB::table('lianhou_stores')
                    ->where(['store_id' => $store_id])
                    ->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;
            case "cmbcUnion":
                $mchinfo = DB::table('cmbcunion_stores')
                    ->where(['store_id' => $store_id])
                    ->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;
            case "czbank":
                $mchinfo = DB::table('czbank_stores')
                    ->where(['store_id' => $store_id])
                    ->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_id;
                }
                break;
            case "gtxy":
                $mchinfo = DB::table("common_mch_stores")->where([
                    "store_id" => $store_id,
                    "company" => $company
                ])->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_no;
                }
                break;
            case "gtxy_v2":
                $mchinfo = DB::table("common_mch_stores_v2")->where([
                    "store_id" => $store_id,
                    "company" => $company
                ])->first();
                if (!empty($mchinfo)) {
                    $mchNo = $mchinfo->mch_no;
                }
                break;
            default:
                $mchNo = "";
        }
        return (string)$mchNo;
    }

}